//
// Created by 11510 on 2024/6/11.
//
#include <iostream>
using namespace std;

// 复数
class Complex{
private:
    int _real;
    int _image;

public:
    Complex(int real, int image):_real(real), _image(image){}

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }

    friend Complex operator+(const Complex& lhs, const Complex &rhs);
};


/**
 * 采用友元函数重载运算符
 * @param lhs
 * @param rhs
 * @return
 */
Complex operator+(const Complex& lhs, const Complex &rhs){
    return Complex(lhs._real + rhs._real, lhs._image + rhs._image);
}



void test0(){
    Complex cx1(1, 2);
    Complex cx2(3, 4);

    Complex cx3 = operator+(cx1, cx2);// 本质
    Complex cx4 = cx1 + cx2;
    cx3.print();
}


int main() {
    test0();
    return 0;
}